#include<stdio.h>
typedef long long LL;
LL pow(LL a,LL b,LL m)
{
	if(b==0) return 1;
	if(b%2)  return a*pow(a,b-1,m)%m;
	else
	{
		LL mul=pow(a,b/2,m);
		return mul*mul%m;
	} 
} 
int main()
{
	LL a,b,m;
	scanf("%lld %lld %lld",&a,&b,&m);
	printf("%lld",pow(a,b,m));
	return 0;
}
